$(function() {
	$("#btn_login").click(function() {
		var username = $("#username").val();
		var password = $("#password").val();
		var flag = true;
		if (username == '' || password == '') {
			flag = false;
			notifyMsg('用户名或密码不能为空');
		}
		if (flag) {
			$.ajax({
				type: "POST",
				url: "http://127.0.0.1:8080/user/login",
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				data: {
					"userName": username,
					"password": password
				},
				success: function(data) {
					var code = data.code;
					if (code == 'success') {
						window.location.href = './index.html';
					} else {
						flag = false;
						notifyMsg(data.msg);
					}
				}
			})
		}
	})
})


function notifyMsg(msg) {
	var notify = $.notify({
		// options
		icon: 'glyphicon glyphicon-warning-sign',
		title: '警告',
		message: msg,
		target: '_blank'
	}, {
		// settings
		element: 'body',
		position: null,
		type: "warning",
		allow_dismiss: true,
		newest_on_top: true,
		showProgressbar: false,
		placement: {
			from: "top",
			align: "center"
		},
		offset: 20,
		spacing: 10,
		z_index: 10001,
		delay: 5000,
		timer: 1000,
		url_target: '_blank'
	});

	return notify;
}
